<?php

namespace app\admin\model;

use think\Model;
use think\Db;
class UserWallet extends Model
{
    // 表名
    protected $name = 'UserEcharge';

    public function left_join($list,$where=null){


        foreach ($list as $key=>&$u){
            $u['add_hj']=0;
            $u['hj']=0;
            $u['shj']=0;
            $u['pt_hj']=0;
            $echoarge=DB::table('cy_user_echarge')->where('user_id='.$u['user_id'].' and is_paid=1')->select();
            foreach ($echoarge as $v){
                if($v['process_type']==0){
                    //充值收入
                    $list[$key]['add_hj']+=$v['amount'];
                }
                //支出退费合计
                if(in_array($v['process_type'],array('2','5','7')))
                $list[$key]['hj'] += $v['amount']*-1;
                if(in_array($v['process_type'],array('1','4','6','8','10','11'))){
                    //收入合计
                    $list[$key]['shj']+=$v['amount'];
                }
                //平台服务费合计
                if($v['process_type']==9){
                    $list[$key]['pt_hj']+=($v['amount']*-1);
                }
                //提现
                $list[$key]['talents']=$echoarge=DB::table('cy_user_echarge')->where('user_id='.$u['user_id'].' and process_type=1')->sum('amount');
            }


        }

        return $list;
    }

    public function charge($list){
        $echarges=Model('Recharge');
        foreach($list as $key=>$v){
            //$list[$key]['id']=DB('user_echarge')->where('user_id='.$v['user_id'])->order('id DESC')->value('id');

            //付费查看收入
            $charges=$echarges->where([
                'user_id' => $v['user_id'],
                'process_type'=>4,
                'user_note'=>array('like','%付费查看收入%')
            ])
                ->sum('amount');
            $list[$key]['resumes']=$charges;
            //简历查看收入
            $charge=$echarges->where([
                'user_id' => $v['user_id'],
                'process_type'=>4,
                'user_note'=>array('like','%查看简历收入%')
            ])
                ->sum('amount');
            /*->get([
                'user_id' => $list['user_id'],
                'process_type'=>4

            ])*/
            $list[$key]['resume']=$charge;
            //有偿分享收入
            $charges=$echarges->where([
                'user_id' => $v['user_id'],
                'process_type'=>10
            ])
                ->sum('amount');
            $list[$key]['share']=$charges;
            //任务悬赏收入
            $chargexs=$echarges->where([
                'user_id' => $v['user_id'],
                'process_type'=>6,

            ])
                ->sum('amount');
            $list[$key]['task']=$chargexs;

        }
        return $list;
    }





}
